<?php
require_once(MODULESPATH . "core/d.object.class.php");
require_once(MODULESPATH . "finance/dataaccess/d.finance.inc.php");

/**
 * 财经系统数据层证券类。
 */
class DStock extends DObject implements IDStock{
    private $pinyin;
    
    /*- IDStock 接口实现 START -*/
    /*- IInjectEnable 接口实现 START -*/
    /**
     * 设置属性值。
     */
    public function __set($prop, $val){
        $this->$prop = $val;
    }
    /*- IInjectEnable 接口实现 END -*/
    
    /**
     * 获取证券列表。
     * @param String $market 证券市场编码。
     * @return 证券列表。
     */
    public function getStocks($market = null){
        $result = array();
        $sql = "select stock_id, stock_symbol, stock_name, stock_type, stock_market from finance_stocks where 1 = 1 ";
        if(($market != null) && (strlen($market) > 0)){
            $sql .= "and stock_market = '$market'";
        }
        try{
            $rows = $this->dao->getData($sql);
            if($rows){
                foreach($rows as $row){
                    $name = $row["stock_name"];
                    $pinyin = $this->pinyin->convert($name);
                    $pinyin = str_replace("*", "", $pinyin);
                    $pinyin = strtoupper($pinyin);
                    $result[] = array(
                        "id" => $row["stock_id"],
                        "symbol" => $row["stock_symbol"],
                        "name" => $name,
                        "pinyin" => $pinyin,
                        "type" => $row["stock_type"],
                        "market" => $row["stock_market"]
                        );
                }
            }
        }catch(Exception $ex){
        }
        return $result;
    }
    /*- IDStock 接口实现 END -*/
}
?>
